package org.softmed.action.implementation;

import org.softmed.action.ActionStep;
import org.softmed.action.builder.ActionStepBuilder;
import org.softmed.action.description.ActionStepDescription;
import org.softmed.action.resolver.ActionStepResolver;

import com.google.inject.Inject;

public class DefaultJavaActionStepResolver implements ActionStepResolver {

	ActionStepBuilder argumentInstantiator = new ActionStepBuilder();

	@Override
	public ActionStep instantiate(ActionStepDescription description)
			throws Throwable {
		String origin = description.getSource();

		// try to get the Java class
		Class<?> type = null;
		try {
			type = Class.forName(origin);
		} catch (ClassNotFoundException e) {
			return null;
		}

		return (ActionStep) argumentInstantiator.getInstance(type, description
				.getParameters());
	}

	public ActionStepBuilder getArgumentInstantiator() {
		return argumentInstantiator;
	}

	public void setArgumentInstantiator(ActionStepBuilder argumentInstantiator) {
		this.argumentInstantiator = argumentInstantiator;
	}

}
